import { IParam, IUIServiceRegister } from '@core';

/**
 * UI服务注册中心
 *
 * @export
 * @class UIServiceRegister
 */
export class UIServiceRegister implements IUIServiceRegister {

    /**
     * UIServiceRegister 单例对象
     *
     * @private
     * @static
     * @memberof UIServiceRegister
     */
    private static UIServiceRegister: UIServiceRegister;

    /**
     * 所有UIService Map对象
     *
     * @private
     * @static
     * @memberof UIServiceRegister
     */
    private static allUIServiceMap: Map<string, any> = new Map();

    /**
     * Creates an instance of UIServiceRegister.
     * @memberof UIServiceRegister
     */
    constructor() {
        this.init();
    }

    /**
     * 获取UIServiceRegister 单例对象
     *
     * @public
     * @static
     * @memberof UIServiceRegister
     */
    public static getInstance() {
        if (!this.UIServiceRegister) {
            this.UIServiceRegister = new UIServiceRegister();
        }
        return this.UIServiceRegister;
    }

    /**
     * 初始化
     *
     * @protected
     * @memberof UIServiceRegister
     */
    protected init(): void {
        UIServiceRegister.allUIServiceMap.set('complianceguide', () => import('@ui-service/compliance-guide/compliance-guide-ui-service'));
        UIServiceRegister.allUIServiceMap.set('lawsupport', () => import('@ui-service/law-support/law-support-ui-service'));
        UIServiceRegister.allUIServiceMap.set('lawpropagandize', () => import('@ui-service/law-propagandize/law-propagandize-ui-service'));
        UIServiceRegister.allUIServiceMap.set('privatelegaldatashare', () => import('@ui-service/private-legal-data-share/private-legal-data-share-ui-service'));
        UIServiceRegister.allUIServiceMap.set('sysemployee', () => import('@ui-service/sys-employee/sys-employee-ui-service'));
        UIServiceRegister.allUIServiceMap.set('hotlawcase', () => import('@ui-service/hot-law-case/hot-law-case-ui-service'));
        UIServiceRegister.allUIServiceMap.set('deptinterface', () => import('@ui-service/dept-interface/dept-interface-ui-service'));
        UIServiceRegister.allUIServiceMap.set('sysrole', () => import('@ui-service/sys-role/sys-role-ui-service'));
        UIServiceRegister.allUIServiceMap.set('sysuserrole', () => import('@ui-service/sys-user-role/sys-user-role-ui-service'));
        UIServiceRegister.allUIServiceMap.set('systodo', () => import('@ui-service/sys-todo/sys-todo-ui-service'));
        UIServiceRegister.allUIServiceMap.set('lawexpress', () => import('@ui-service/law-express/law-express-ui-service'));
        UIServiceRegister.allUIServiceMap.set('complianceissue', () => import('@ui-service/compliance-issue/compliance-issue-ui-service'));
    }

    /**
     * 获取指定UIService
     *
     * @param {string} entityKey 应用实体名小写
     * @param {*} context 应用上下文
     * @return {*} 
     * @memberof UIServiceRegister
     */
    public async getService(entityKey: string, context: IParam = {}) {
        const importService = UIServiceRegister.allUIServiceMap.get(entityKey);
        if (importService) {
            const importModule = await importService();
            return importModule.default.getInstance(context);
        }
    }

}